<?php
/*mysql.closs.php
*Location:
*/
class mysql{
var $link;
var $config=array();
function __construct($config)
{
$this->config=$config;
$this->connect();
}
function connect()
{
if($this->config['pconnect']==0)
{
$this->link=@mysql_connect($this->config['dbhost'],$this->config['dbuser'],$this->config['dbpass']);
}
else{
$this->link=@mysql_pconnect($this->config['dbhost'],$this->config['dbuser'],$this->config['dbpass']);
}
if($this->link==NULL)
{
throw new Exception("can not connect to mysql server".mysql_error());
}
if(!mysql_select_db($this->config['dbname'],$this->link))
{
throw new Exception('Database error '.mysql_error());
}
$this->query("set names 'UTF8'");
}
function query($sql)
{
$result=mysql_query($sql,$this->link) or die(mysql_error());
return $result;
}
function get_str($value)
{
if (get_magic_quotes_gpc()){
  $value = stripslashes($value);
  }
$value = "'" . mysql_real_escape_string($value) . "'";
return $value;
}
function fetch_first($sql)
{
$result=$this->query($sql);
if(!$result)
{return false;}
$row=mysql_fetch_array($result);
mysql_free_result($result);
return $row;
}
function fetch_all($sql)
{
$return=array();
$num=0;
$result=$this->query($sql);
if(!$result)
{
return false;
}
while($row=mysql_fetch_array($result))
{
$return[$num++]=$row;
}
return $return;
}
function tpre($table)
{
if(!is_array($table))
{return $this->config['tpre'].$table;}
else{
	$r="";
	foreach($table as $t){
	$r=$r.$this->config['tpre'].$t.'` , `';
	}
	return substr($r,0,-3);
	}
}
}
